
import 'dart:math';
import 'dart:ui';

import 'package:demo202112/utils/common_appbar.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
/**
 * @Author wywinstonwy
 * @Date 2022/1/3 11:02 上午
 * @Description:
 */

class MyShows extends StatefulWidget {
  const MyShows({Key? key}) : super(key: key);

  @override
  _MyShowsState createState() => _MyShowsState();
}

class _MyShowsState extends State<MyShows> {

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

  }



  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: getAppBar('flutter各种show'),
      body: Container(
        child: Column(
          // mainAxisSize: MainAxisSize.max,
          children: [
            ElevatedButton(onPressed: _ontapshowDialog, child: Text('showDialog')),
            ElevatedButton(onPressed: _ontapCupertinoDialog, child: Text('showCupertinoDialog')),
            ElevatedButton(onPressed: _ontapshowGeneralDialog, child: Text('showGeneralDialog')),
            ElevatedButton(onPressed: _ontapshowAboutDailg, child: Text('showAboutDialog')),
            ElevatedButton(onPressed: _ontapshowLicensePage, child: Text('showLicensePage')),
            ElevatedButton(onPressed: _ontapshowBottomSheet, child: Text('showBottomSheet')),
            ElevatedButton(onPressed: _ontapshowModalBottomSheet, child: Text('showModalBottomSheet')),
            ElevatedButton(onPressed: _ontapshowCupertinoModalPopup, child: Text('showCupertinoModalPopup')),
            ElevatedButton(onPressed: _ontapshowMenu, child: Text('showMenu')),
            ElevatedButton(onPressed: _ontapshowSearch, child: Text('showSearch')),
          ],
        ),
      ),
    );
  }
  _ontapshowDialog(){
    showDialog(context: context,
        barrierDismissible: true,
        builder: (context){
      return AlertDialog(
        title: Text('温馨提示'),
        content: Text('确定要删除吗？'),
        actions: [
          ElevatedButton(onPressed: (){
            Navigator.of(context).pop(false);
          }, child: Text('取消')),
          ElevatedButton(onPressed: (){
            Navigator.of(context).pop(true);

          }, child: Text('确认')),
        ],
      );
    });
  }
  _ontapCupertinoDialog(){
    showCupertinoDialog(context: context, builder: (context){
      return CupertinoAlertDialog(
      title: Text('温馨提示'),
      content: Text('确定要删除吗？'),
      actions: [
      CupertinoButton(onPressed: (){
      Navigator.of(context).pop(false);
      }, child: Text('取消')),
        CupertinoButton(onPressed: (){
      Navigator.of(context).pop(true);

      }, child: Text('确认')),
      ],
      );
    });
  }
  _ontapshowGeneralDialog(){
      showGeneralDialog(
        barrierDismissible: true,
         barrierLabel: '测试',
         transitionBuilder: (BuildContext context,Animation<double> animation,Animation<double>secondaryAnimation,Widget child){
           return ScaleTransition(scale: animation,child: child,);
         },
          context: context,
          barrierColor: Colors.black.withOpacity(0.6),
          pageBuilder: (BuildContext context,Animation<double> animation,Animation<double>secondaryAnimation){
            return Center(
              child: Stack(
                alignment: Alignment.center,
                children: [
                  Container(
                    height: 250,
                    width: 200,
                    color: Colors.lightBlueAccent,
                  ),
                  Container(
                    height: 100,
                    width: 100,
                    color: Colors.yellow,
                  )
                ],
              ),
            );
          });
  }
  _ontapshowAboutDailg(){
    showAboutDialog(
        context: context,
      applicationIcon: Image.network('https://img0.baidu.com/it/u=3335395408,3367072408&fm=26&fmt=auto',height: 100,width: 100,),
      applicationName: '汽车头条',
      applicationVersion: '9.1.5',
      applicationLegalese: 'copyright 汽车资讯第一站',
      children: [
        Container(height: 200,color: Colors.yellow,child: Text('汽车头条于2014年4月成立于北京，隶属于北京智阅网络科技有限公司。专注于移动互联的汽车类垂直内容资讯网站，结合智能搜索、兴趣推荐、内容聚合等技术，为用户打造和提供全面、准确汽车资讯的内容平台。'),),
        Container(height: 300,child: Text('汽车头条APP，你的汽车移动资讯站。专注于移动端的专业汽车传播平台；能够迅速掌握你的阅读兴趣点，提供真正有价值的汽车资讯；我们以汽车爱好者、汽车消费者和汽车从业者为核心用户，通过新车、行业、科技几大板块，传递你所关心的汽车资讯。我们的使命是，重塑汽车移动传播链条，打造精准汽车资讯站点，满足用户在移动互联网时代悦读车闻以及参与车闻创作的需求。 [1]  '),),

      ],
    );
  }
  _ontapshowLicensePage(){
    showLicensePage(
      context: context,
      applicationIcon: Image.network('https://img0.baidu.com/it/u=3335395408,3367072408&fm=26&fmt=auto',height: 100,width: 100,),
      applicationName: '测试数据名称',
      applicationVersion: 'V 1.1.1',
      applicationLegalese: 'copyright 汽车资讯第一站',

    );
  }
  _ontapshowBottomSheet(){
    showBottomSheet(

        context: context,
        builder: (BuildContext context){
      return Container(
        height: 200,
        color: Colors.lightBlueAccent,
      );
    });
  }
  _ontapshowModalBottomSheet(){
    showModalBottomSheet(
        context: context,
        isScrollControlled: true,
        builder: (BuildContext context) {
          return ListView.builder(
            itemBuilder: (context, index) {
              return ListTile(
                title: Center(child: Text('是否可以点击背景关闭$index'),),
              );
            },
            itemExtent: 50,
            itemCount: 50,
          );
        });
  }
  _ontapshowCupertinoModalPopup(){
    showCupertinoModalPopup(
        context: context,
        filter: ImageFilter.blur(sigmaX: 0.5,sigmaY: 5.0),
        builder: (context){
          return CupertinoActionSheet(
            title: Text('提示'),
            message: Text('是否删除当前选项'),
            actions: [
              CupertinoActionSheetAction(onPressed: (){}, child: Text('删除'),isDefaultAction: true,),
              CupertinoActionSheetAction(onPressed: (){}, child: Text('暂时不删'),isDestructiveAction: true,),
            ],
          );
        });
  }
  _ontapshowMenu(){

    showMenu(
        context: context,
        position: RelativeRect.fill,
        items: <PopupMenuEntry>[
          PopupMenuItem(child: Text('语文'),onTap: (){
            print('语文');
          },),
          PopupMenuDivider(),
          CheckedPopupMenuItem(
            checked: true,
            child: Text('数学'),
          ),
          PopupMenuDivider(),
          PopupMenuItem(child: Text('政治')),
          PopupMenuDivider(),
          PopupMenuItem(child: Text('英语')),
          PopupMenuDivider(),
          PopupMenuItem(child: Text('体育')),




        ]
    );
  }
  _ontapshowSearch(){
    showSearch(context: context, delegate: CustomSearchDelegate());
  }
  _onClosing(){

  }
}
class CustomSearchDelegate extends SearchDelegate<String>{
  @override
  List<Widget> buildActions(BuildContext context) {
    return [
      IconButton(
        icon: Icon(
          Icons.clear,
        ),
        onPressed: () {
          query = '';
        },
      )
    ];
  }

  @override
  Widget buildLeading(BuildContext context) {
    return IconButton(
      icon: Icon(Icons.arrow_back,color: Colors.blue,),
      onPressed: (){
        close(context, '');
      },
    );
  }
//buildResults是构建搜索结果控件，当用户点击软键盘上的“Search”时回调此方法，一般返回ListView，
  @override
  Widget buildResults(BuildContext context) {
    return ListView.separated(
      itemBuilder: (context, index) {
        return Container(
          height: 60,
          alignment: Alignment.center,
          child: Text(
            '$index',
            style: TextStyle(fontSize: 20),
          ),
        );
      },
      separatorBuilder: (context, index) {
        return Divider();
      },
      itemCount: 10,
    );
  }
  //
  @override
  Widget buildSuggestions(BuildContext context) {
      return ListView.separated(
      itemBuilder: (context, index) {
        return ListTile(
          title: Text('测试 $index'),
          onTap: () {
            query = '测试 $index';
          },
        );
      },
      separatorBuilder: (context, index) {
        return Divider();
      },
      itemCount: Random().nextInt(5),
    );
    return Container(
      height: 200,
      color: Colors.lightGreen,
    );
  }

}
